<style lang="less">
@import url('./app.less');
</style>

<template>
  <div id="app">
    <div class="main-container">
      <div v-if="$env==='development'" class="menu-container">
        <side-menu />
      </div>
      <div class="main-content">
        <router-view/>
      </div>

    </div>
  </div>
</template>
<script>
import SideMenu from '_c/layout/SideMenu'
import Cookie from 'js-cookie'
export default {
  name: 'app',
  components: {
    SideMenu
  },
  data () {
    return {}
  },
  mounted () {
    let token = this.getToken('token') || Cookie.get('token')// 开发用
    window.sessionStorage.setItem('token', token)

    window.addEventListener('message', event => {
      const data = event.data
      if (data.type) {
        // console.log('地图消息：' + JSON.stringify(data, null, 4))
        switch (data.type) {
          case 'on-route':
            this.$router.push({
              name: data.payload.name
            })
            break
        }
      }
    })
  },
  methods: {
    getToken (key) {
      let query = window.location.search.substring(1)
      let vars = query.split('&')
      for (let i = 0; i < vars.length; i++) {
        var pair = vars[i].split('=')
        if (pair[0] === key) { return decodeURI(pair[1]) }
      }
      return ''
    }
  }
}
</script>
